package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.system.SystemNoticeBo;
import com.cw.jeeyt.dao.model.system.SystemNoticeDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 公告通知转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemNoticeConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemNoticeBo do2Bo(SystemNoticeDo model) {
        if (model == null) {
            return null;
        }
        String isPublicCn = StringUtil.isNotBlank(model.getIsPublic()) ? EnumYn.find(model.getIsPublic())
            .getDescription() : "";
        SystemNoticeBo bo = new SystemNoticeBo();
        bo.setId(model.getId());
        bo.setNoticeName(model.getNoticeName());
        bo.setNoticeTitle(model.getNoticeTitle());
        bo.setNoticeContent(model.getNoticeContent());
        bo.setIsPublic(model.getIsPublic());
        bo.setIsPublicCn(isPublicCn);
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemNoticeDo bo2Do(SystemNoticeBo bo) {
        if (bo == null) {
            return null;
        }
        SystemNoticeDo model = new SystemNoticeDo();
        model.setId(bo.getId());
        model.setNoticeName(bo.getNoticeName());
        model.setNoticeTitle(bo.getNoticeTitle());
        model.setNoticeContent(bo.getNoticeContent());
        model.setIsPublic(bo.getIsPublic());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemNoticeBo> doList2BoList(List<SystemNoticeDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemNoticeConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemNoticeDo> boList2DoList(List<SystemNoticeBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemNoticeConverter::bo2Do));
    }
}
